<div class="page-header">
    <h1>
        管理员信息列表
        <small>
            <i class="ace-icon fa fa-angle-double-right"></i>
        </small>
    </h1>
</div>
<div class="row">
    <div class="col-xs-12">
        <table id="dtpList" class="dataTable"></table>
        <div id="dtpList_filter" class="dataTables_filter">
            <div>
                <select id="dtpList_F_SType" class="selectpicker" data-style="btn btn-info btn-sm" data-width="90px">
                    <option value="">模糊查询</option>
                    <option data-divider="true"></option>
                    <option value="User_ID">用户ID</option>
                    <option value="NickName">用户昵称</option>
                    <option value="RealName">真实姓名</option>
                    <option value="Phone">手机号</option>
                </select>
                <input id="dtpList_F_SValue" class="fvalue" type="text"/>
                <input id="dtpList_F_StartDate" type="text" style="width: 76px;" placeholder="开始时间">
                <label>-</label>
                <input id="dtpList_F_EndDate" type="text" style="width: 76px;" placeholder="结束时间">
                <select id="dtpList_F_SelectDate"></select>
                <label><input id="dtpList_F_IsMaster" type="checkbox"/>&nbsp;超级管理员</label>
                <label>状态：</label>
                <select id="dtpList_F_Status">
                    <option value="-1">所有</option>
                    <option value="0" selected="selected">正常</option>
                    <option value="1">锁定</option>
                </select>
                <button id="dtpList_F_Btn"></button>
            </div>
        </div>
    </div>
</div>
<script src="<%- Virtual_Path.Static %>jquery.plugin/dataTables/jquery.dataTables.min.js"></script>
<script src="<%- Virtual_Path.Static %>jquery.plugin/dataTables/jquery.dataTables.bootstrap.min.js"></script>
<script>
    $(function () {
        //region 时间输入框插件
        $('#dtpList_F_StartDate, #dtpList_F_EndDate').datetimepicker({
            language: 'zh-CN',
            format: 'yyyy-mm-dd',
            minView: 2,
            autoclose: true
        });
        //endregion
        //region 绑定日期选择框
        $.KOC.Date.Select.Bind({
            eSelect: $('#dtpList_F_SelectDate'),
            eBegin: $('#dtpList_F_StartDate'),
            eEnd: $('#dtpList_F_EndDate')
        });
        //endregion
        //region dtpList
        var _dtpList = $("#dtpList").dataTable({
            'aoColumns': [
                {
                    'sWidth': '93px', 'data': 'User_ID', 'sName': 'User_ID', 'sTitle': 'ID', 'sClass': 'center',
                    'createdCell': function (td, cellData) {
                        $(td).html($('<a/>').attr('data-openwindow', ':UserAdminInfo:' + cellData).text(cellData));
                    }
                },
                {
                    'data': 'RealName', 'sTitle': '姓名', 'sClass': 'center t-left', bSortable: false
                },
                {
                    'sWidth': '13%', 'data': 'Phone', 'sTitle': '手机号码', 'sClass': 'center', bSortable: false
                },
                {
                    'sWidth': '60px', 'data': 'IsMaster', 'sName': 'IsMaster', 'sTitle': '超管', 'sClass': 'center',
                    'createdCell': function (td, cellData) {
                        $(td).text(cellData ? '是' : '否');
                    }
                },
                {
                    'sWidth': '13%', 'data': 'Create_Date', 'sName': 'Order_No', 'sTitle': '时间', 'sClass': 'center',
                    'createdCell': function (td, cellData) {
                        $(td).text(moment(cellData).format('YY/MM/DD HH:mm'));
                    }
                },
                {
                    'sWidth': '65px', 'data': 'Status', 'sName': 'Status', 'sTitle': '状态', 'sClass': 'center',
                    'createdCell': function (td, cellData) {
                        switch (cellData) {
                            case 0:
                                $(td).html('<span class="label label-success">正常</span>');
                                break;
                            case 1:
                                $(td).html('<span class="label label-danger">锁定</span>');
                                break;
                            default:
                                $(td).html('<span class="label label-default">未知</span>');
                                break;
                        }
                    }
                }
            ],
            'aaSorting': [0, 'desc'],
            'sAjaxSource': '/ajax/user.page.useradmin',
            'fnServerParams': function (aoData) {
                if (!this.arrPageFilter) {
                    this.arrPageFilter = {
                        F_IsMaster: $(this.selector + '_F_IsMaster').is(':checked') ? 1 : -1,
                        F_StartDate: $(this.selector + '_F_StartDate').val(),
                        F_EndDate: $(this.selector + '_F_EndDate').val(),
                        F_Status: $(this.selector + '_F_Status').val()
                    };
                } else {
                    $(this.selector + '_F_IsMaster').val(this.arrPageFilter.F_IsMaster);
                    $(this.selector + '_F_StartDate').val(this.arrPageFilter.F_StartDate);
                    $(this.selector + '_F_EndDate').val(this.arrPageFilter.F_EndDate);
                    $(this.selector + '_F_Status').val(this.arrPageFilter.F_Status);
                }
                this.ofnServerParams(aoData);
            },
            'fnDrawCallback': function () {
                $.Common.Bootstrap.Tooltip(this);
                this.ofnDrawCallback();
            },
            'selectOpt': {
                Tools: {
                    Init: true,
                    Buttons: {
                        'btn-Add': {
                            text: '<i class="fa fa-pencil"></i> 添加',
                            style: 'primary',
                            'data-permission-code': '{User}[Admin](Edit)',
                            action: function () {
                                $.CommonAdmin.OpenWindow(':UserAdminEdit:', function () {
                                    _dtpList.fnDraw();
                                });
                                return false;
                            }
                        },
                        'btn-Edit': {
                            text: '<i class="fa fa-pencil"></i> 修改',
                            style: 'primary',
                            addClass: 'btn disabled',
                            'data-permission-code': '{User}[Admin](Edit)',
                            action: function () {
                                $.CommonAdmin.OpenWindow(':UserAdminEdit:' + _dtpList.selectData.User_ID, function () {
                                    _dtpList.fnDraw();
                                });
                                return false;
                            }
                        },
                        'btn-Info': {
                            text: '<i class="fa fa-search"></i> 查看',
                            style: 'primary',
                            addClass: 'btn disabled',
                            'data-permission-code': '{User}[Admin](Info)',
                            action: function () {
                                $.CommonAdmin.OpenWindow(':UserAdminInfo:' + _dtpList.selectData.User_ID, function () {
                                    _dtpList.fnDraw();
                                });
                                return false;
                            }
                        },
                        'btn-close': {}
                    },
                    onBuild: function (content) {
                        $.CommonAdmin.Permission.CheckElement(content);
                    },
                    onReset: function () {
                        if (!_dtpList.selectData) {
                            return;
                        }
                        var _btn = ['btn-Info', 'btn-Add', 'btn-Edit'];
                        _dtpList.ofnSelectToolsBtnRemoveClass(_btn);
                    }
                }
            }
        });
        //endregion
    });
</script>